<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>查看方案</title>
    <script type="text/javascript" src="../../res/js/jquery-3.4.1.min.js"></script>
    <script type="text/javascript" src="../../layui/layui.js"></script>
    <script type="text/javascript" src="../../js/Tools.js"></script>
    <script type="text/javascript" src="../../js/login_common.js"></script>
    <link rel="stylesheet" href="../../layui/css/layui.css">
    <style>
        body{
            padding: 10px 20px 10px 10px;
        }
        .title_font{
            font-weight: bold;
        }

    </style>
</head>
<body>
    <table class="layui-table" lay-even="" lay-skin="nob">
        <colgroup>
            <col width="100">
            <col width="150">
        </colgroup>
        <thead>
        <tr>
            <td class="title_font">方案名称</td>
            <td id="schemeName" style="width: 300px"></td>
            <td class="title_font">方案类型</td>
            <td id="schemeType"></td>
        </tr>
        </thead>
        <tbody>

        <tr>
            <td class="title_font">教练员</td>
            <td id="coachName"></td>
            <td class="title_font">创建时间</td>
            <td id="creatTime"></td>
        </tr>
        <tr>
            <td class="title_font">运动员</td>
            <td id="athleteName"></td>
            <td class="title_font">创建人</td>
            <td id="creater"></td>
        </tr>

        <tr>
            <td class="title_font">实施情况</td>
            <td id="resultExp" colspan="3"></td>
        </tr>
        <tr>
            <td class="title_font">实施效果</td>
            <td id="resultEffect" colspan="3"></td>
        </tr>
        <tr>
            <td class="title_font">反馈时间</td>
            <td id="resultTime"></td>
            <td class="title_font">申请咨询状态</td>
            <td id="auditState"></td>

        </tr>
        <tr>
            <td style="width: 100px" class="title_font">专家咨询结果</td>
            <td id="results" colspan="3"></td>
        </tr>
        <tr>
            <td class="title_font">附件一</td>
            <td id="file1"></td>
            <td class="title_font">附件二</td>
            <td id="file2"></td>
        </tr>
        <tr>
        </tr>
        <tr>
            <td class="title_font">附件三</td>
            <td id="file3"></td>
            <td class="title_font">实施附件</td>
            <td id="resultFile"></td>
        </tr>


        </tbody>
    </table>
    <form class="layui-form" id="commentForm">
        <input type="hidden" id="schemeId"/>
        <div class='layui-form-item layui-form-text'>
           <label class='layui-form-label'>建议</label>
            <div class='layui-input-block'>
                <textarea placeholder='请输入您的意见和建议' id='exp' name='exp' lay-verify='exp' class='layui-textarea'></textarea>
                </div>
            </div>
        <div class='layui-form-item'>
        <div class='layui-input-block'>
            <input type='button' class='layui-btn' lay-submit='' id="button" lay-filter='demo1' value="立即提交"/>
            </div>
        </div>

    </form>
    <script>


        //取上个页面传过来的方案id
        var schemeId=getQueryString("schemeId");

        layui.use(['form', 'layedit', 'laydate','tree','element','upload'], function () {
            var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate
                , element = layui.element
                , upload = layui.upload;

                //自定义验证规则
                form.verify({
                    exp: function (value) {
                        if (!value.length) {
                            return '意见框不能包含空格';
                        }else if(loginObj.manager.companyNum!=="4"){
                            console.info(loginObj.manager.companyNum);
                            return '您不是运动员，不能提意见哦！';
                        }
                    }
                });

                //监听提交
                form.on('submit(demo1)', function (data) {

                    var url2 = getRootPath() + "atsSchemeAction/addExp";
                    var data2 = {schemeId: schemeId, exp:$("#exp").val()};
                    $.ajax({
                        url: url2,
                        type: "post",
                        data: data2,
                        dataType: "json",
                        success: function (obj) {

                                layer.msg(obj.msg, {
                                    icon: 1,
                                    time: 1000,
                                }, function () {
                                    window.parent.location.reload();//刷新父页面
                                    var index = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(index);
                                });
                        }, error: function (e) {
                            alert('失败了');
                        }

                    });
                });
            });


        //根据id查询方案信息
        var url = getRootPath() + "atsSchemeAction/selectById";
        var data = {schemeId: schemeId};
        $.post(url, data, function (obj) {
            $("#schemeId").val(obj.schemeId);
            $("#schemeName").text(obj.schemeName);
            if(obj.schemeType==1){
                $("#schemeType").text("运动康复方案");
            }else if(obj.schemeType==2){
                $("#schemeType").text("运动营养方案");
            }else if(obj.schemeType==3){
                $("#schemeType").text("心理训练方案");
            }
            $("#results").text(obj.results);
            $("#creatTime").text(getMyDate(obj.creatTime));
            $("#coachName").text(obj.coachName);

            //查询专家咨询结果
            var url2 = getRootPath() + "atsSchemeAction/selectAuExp";
            var data2 = {schemeId: schemeId};
            var state="";
            $.post(url2, data2, function (obj2) {
                if(obj2.auditState==='10'){
                    state="已提交申请";
                }else if(obj2.auditState==='20'){
                    state="领导已同意";
                }else if(obj2.auditState==='21'){
                    state="领导未同意";
                }else if(obj2.auditState==='30'){
                    state="专家已查看";
                }else if(obj2.auditState==='40'){
                    state="专家已回复";
                }
                $("#auditState").text(state);
                $("#results").text(obj2.results);

            });


                //查询运动员
                var url1 = getRootPath() + "atsSchemeAction/selectAthleteById";
                var data1 = {schemeId: schemeId};
                $.post(url1, data1, function (obj1) {
                    var str="";
                    $.each(obj1,function (index,item) {
                        if(item.athleteName){
                            str+=item.athleteName+"、";
                        }
                    });
                    str=str.substr(0,str.length-1);
                    $("#athleteName").text(str);
                });
                $("#creater").text(obj.creater);
                $("#resultExp").text(obj.resultExp);
                $("#resultEffect").text(obj.resultEffect);
                $("#resultTime").text(obj.resultTime);
                if(obj.file1){
                    $("#file1").append('<a class="layui-btn layui-bg-blue layui-btn-xs" target="_blank" href="../../'+obj.file1+'">下载</a>');
                }
                if(obj.file2){
                    $("#file2").append('<a class="layui-btn layui-bg-blue layui-btn-xs" target="_blank" href="../../'+obj.file2+'">下载</a>');
                }
                if(obj.file3){
                    $("#file3").append('<a class="layui-btn layui-bg-blue layui-btn-xs" target="_blank" href="../../'+obj.file3+'">下载</a>');
                }
                $("#resultFile").append('<a class="layui-btn layui-bg-blue layui-btn-xs" target="_blank" href="../../'+obj.resultFile+'">下载</a>');
                $("#remark").text(obj.remark);


            }, "json");








        /**
         *时间转换格式
         * @param str
         * @returns
         */
        function getMyDate(str){
            var oDate = new Date(str),
                oYear = oDate.getFullYear(),
                oMonth = oDate.getMonth()+1,
                oDay = oDate.getDate(),
                oTime = oYear +"-"+ getzf(oMonth) +"-"+ getzf(oDay);//最后拼接时间
            return oTime;
        };

        //补0操作
        function getzf(num){
            if(parseInt(num) < 10){
                num = '0'+num;
            }
            return num;
        }

    </script>
</body>
</html>